import request from '@/utils/request'
import store from '@/store'
// 查询GeneralUserNotice列表
export function listGeneralUserNotice(query) {
    return request({
        url: '/api/v1/noticeList',
        method: 'get',
        params: query
    }).then(function (res) {
        
        let noticeTypeOptions = store.getters.parameter.general_user_notice_type;
        let boolOptions = store.getters.parameter.sys_bool;
       
        res.data.list.forEach((item, index) => {
            
            for (let key in item) {
                
                if (key == "noticeType") {
                    item["noticeTypeValue"] = item[key]
                    item[key] = getDictLabelByValue(item[key],noticeTypeOptions) 
                }
                if (key == "isRead") {
                    item[key] = getDictLabelByValue(item[key],boolOptions)
                }
               

            }
             
            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}

function getDictLabelByValue(value,dict_list){
    let dictLabel="";
    if(dict_list){
        dict_list.forEach((_item,index)=>{
            if(_item.dictValue==value){
                dictLabel= _item.dictLabel
            }
        })
        return dictLabel;
    }else{
        console.log(value);
        return ;
    }
    
}

// 新增GeneralUserNotice
export function addGeneralUserNotice(data, userIds) {
    return request({
        url: '/api/v1/notice',
        method: 'post',
        data: data,
        params: {
            userIds: userIds
        }
    })
}



// 删除GeneralUserNotice
export function delGeneralUserNotice(noticeId) {
    return request({
        url: '/api/v1/notice/' + noticeId,
        method: 'delete'
    })
}